<template>
  <view class="personal-center">
    <!-- 顶部背景和用户信息 -->
    <view class="user-header">
      <image class="header-bg" src="/static/images/user-bg.jpg" mode="scaleToFill"></image>
      <view class="user-info">
        <view class="avatar-box">
          <image class="avatar" :src="userInfo.avatar || '/static/images/default-avatar.png'" mode="aspectFill"></image>
          <text class="edit-avatar" @click="changeAvatar">编辑</text>
        </view>
        <view class="info-box">
          <text class="username">{{userInfo.nickname || '未设置昵称'}}</text>
          <text class="user-id">ID: {{userInfo.userId}}</text>
        </view>
      </view>
    </view>

    <!-- 数据统计 -->
    <view class="data-stats">
      <view class="stat-item" v-for="(item, index) in statsData" :key="index" @click="handleStatClick(index)">
        <text class="stat-value">{{item.value}}</text>
        <text class="stat-label">{{item.label}}</text>
      </view>
    </view>

    <!-- 功能菜单 -->
    <view class="menu-section">
      <view class="section-title">我的服务</view>
      <view class="menu-grid">
        <view class="menu-item" v-for="(item, index) in menuItems" :key="index" @click="navigateTo(item.path)">
          <image class="menu-icon" :src="item.icon" mode="aspectFit"></image>
          <text class="menu-text">{{item.title}}</text>
        </view>
      </view>
    </view>

    <!-- 设置选项 -->
    <view class="settings-section">
      <view class="section-title">设置</view>
      <view class="setting-item" v-for="(item, index) in settings" :key="index" @click="navigateTo(item.path)">
        <text class="setting-text">{{item.title}}</text>
        <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      userInfo: {
        avatar: '',
        nickname: '张三',
        userId: '12345678'
      },
      statsData: [
        { label: '关注', value: 128 },
        { label: '粉丝', value: 56 },
        { label: '获赞', value: 1024 },
        { label: '收藏', value: 32 }
      ],
      menuItems: [
        { title: '我的订单', icon: '/static/icons/order.png', path: '/pages/order/list' },
        { title: '我的收藏', icon: '/static/icons/favorite.png', path: '/pages/favorite/list' },
        { title: '我的钱包', icon: '/static/icons/wallet.png', path: '/pages/wallet/index' },
        { title: '我的地址', icon: '/static/icons/address.png', path: '/pages/address/list' },
        { title: '客服中心', icon: '/static/icons/service.png', path: '/pages/service/index' },
        { title: '关于我们', icon: '/static/icons/about.png', path: '/pages/about/index' }
      ],
      settings: [
        { title: '账号设置', path: '/pages/settings/account' },
        { title: '隐私设置', path: '/pages/settings/privacy' },
        { title: '通知设置', path: '/pages/settings/notification' },
        { title: '通用设置', path: '/pages/settings/general' }
      ]
    }
  },
  methods: {
    changeAvatar() {
      uni.chooseImage({
        count: 1,
        success: (res) => {
          this.userInfo.avatar = res.tempFilePaths[0]
          // 这里可以上传到服务器
        }
      })
    },
    navigateTo(path) {
      if (path) {
        uni.navigateTo({
          url: path
        })
      }
    },
    handleStatClick(index) {
      // 处理数据统计项的点击
      const paths = [
        '/pages/follow/list',
        '/pages/fans/list',
        '/pages/likes/list',
        '/pages/favorite/list'
      ]
      this.navigateTo(paths[index])
    }
  }
}
</script>

<style lang="scss">
.personal-center {
  background-color: #f5f5f5;
  min-height: 100vh;
  padding-bottom: 30rpx;
}

.user-header {
  position: relative;
  height: 320rpx;
  
  .header-bg {
    width: 100%;
    height: 100%;
    filter: blur(2px);
  }
  
  .user-info {
    position: absolute;
    bottom: -80rpx;
    left: 30rpx;
    right: 30rpx;
    display: flex;
    align-items: flex-end;
    z-index: 2;
    
    .avatar-box {
      position: relative;
      margin-right: 30rpx;
      
      .avatar {
        width: 160rpx;
        height: 160rpx;
        border-radius: 50%;
        border: 4rpx solid #fff;
        background-color: #fff;
      }
      
      .edit-avatar {
        position: absolute;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        color: #fff;
        font-size: 20rpx;
        padding: 4rpx 10rpx;
        border-radius: 20rpx;
      }
    }
    
    .info-box {
      margin-bottom: 20rpx;
      
      .username {
        display: block;
        font-size: 36rpx;
        font-weight: bold;
        color: #fff;
        margin-bottom: 10rpx;
        text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.3);
      }
      
      .user-id {
        font-size: 24rpx;
        color: #eee;
      }
    }
  }
}

.data-stats {
  display: flex;
  background-color: #fff;
  margin: 100rpx 30rpx 30rpx;
  padding: 30rpx 0;
  border-radius: 16rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  
  .stat-item {
    flex: 1;
    text-align: center;
    
    .stat-value {
      display: block;
      font-size: 36rpx;
      font-weight: bold;
      color: #333;
      margin-bottom: 10rpx;
    }
    
    .stat-label {
      font-size: 24rpx;
      color: #999;
    }
  }
}

.menu-section, .settings-section {
  background-color: #fff;
  margin: 30rpx;
  border-radius: 16rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  overflow: hidden;
  
  .section-title {
    padding: 20rpx 30rpx;
    font-size: 28rpx;
    color: #666;
    border-bottom: 1rpx solid #f5f5f5;
  }
}

.menu-grid {
  display: flex;
  flex-wrap: wrap;
  padding: 20rpx 0;
  
  .menu-item {
    width: 25%;
    padding: 20rpx 0;
    text-align: center;
    
    .menu-icon {
      width: 60rpx;
      height: 60rpx;
      margin-bottom: 10rpx;
    }
    
    .menu-text {
      display: block;
      font-size: 24rpx;
      color: #666;
    }
  }
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 25rpx 30rpx;
  border-bottom: 1rpx solid #f5f5f5;
  
  &:last-child {
    border-bottom: none;
  }
  
  .setting-text {
    font-size: 28rpx;
    color: #333;
  }
}
</style>
